Option Strict Off
Option Explicit On
Namespace BMLERP
	Friend Class frmChangePassword
		Inherits System.Windows.Forms.Form

		Private Sub frmChangePassword_Activated(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Activated
			UserName.Text = UserLogin.ToString()
			Adodc1.ConnectionString = ConnectString
			Adodc1.CommandTimeout = 10
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc1.RecordSource = "Select Users.* from Users where (((Users.UserName) ='" & UserLogin & "'))"
			Adodc1.Refresh()
			Adodc1.Recordset.MoveFirst()
		End Sub

		Private Sub frmChangePassword_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
			lbpswnew1.Visible = False
			lbpswnew2.Visible = False
			newpsw1.Visible = False
			newpsw2.Visible = False
			Adodc1.ConnectionString = ConnectString
			Adodc1.CommandTimeout = 10
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc1.RecordSource = "Select Users.* from Users where (((Users.UserName) ='" & UserLogin & "'))"
			Adodc1.Refresh()
			Adodc1.Recordset.MoveFirst()

			VB6_AddADODataBinding()
		End Sub

		Private Sub newpsw1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles newpsw1.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

			If KeyAscii = 13 Then
				lbpswnew2.Visible = True
				newpsw2.Visible = True
				newpsw2.Focus()
			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub


		Private Sub newpsw2_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles newpsw2.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim cmdExecute As Object
			If KeyAscii = 13 Then
				If newpsw2.Text = newpsw1.Text Then
					cmdExecute = New ADODB.Command
					cmdExecute.ActiveConnection = DBconn
					cmdExecute.CommandText = ("UPDATE Users SET " & " password ='" & encode((newpsw2.Text)) & "'" & " WHERE username='" & UserName.Text & "'")
					cmdExecute.Execute()
					MsgBox("Password has been changed !")
					Me.Close()
				Else
					MsgBox("Wrong Password. Please input again")
					newpsw1.Focus()
					newpsw1.Text = ""
					newpsw2.Text = ""
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub


		Private Sub ok_Click()
		End Sub

		Private Sub oldpsw_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles oldpsw.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				With Adodc1.Recordset
					.MoveFirst()
					Do Until .Fields("UserName").Value = UserName.Text
						.MoveNext()
					Loop
				End With
				Dim pass As String = Adodc1.Recordset.Fields("Password").Value
				If encode((oldpsw.Text)) = encode(Adodc1.Recordset.Fields("Password").Value) Then
					lbpswold.Visible = False
					oldpsw.Visible = False
					lbpswnew1.Visible = True
					newpsw1.Visible = True
					newpsw1.Focus()
				Else
					MsgBox("Wrong Old Password. Please Re-input!")
					oldpsw.Focus()
				End If
			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub


		Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
			Me.Close()
		End Sub
	End Class
End Namespace